package com.uinnova.product.eam.init.cassso;

import com.binary.framework.web.RemoteResult;
import com.uinnova.project.base.diagram.exception.LoginFailException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @description: 单点登录异常处理
 * @author: LiMG
 * @create: 2024-05-30 17:56:46
 **/
@ControllerAdvice
@Order(0)
public class CASExceptionHandler {

    private static Logger logger = LoggerFactory.getLogger(CASExceptionHandler.class);

    @ExceptionHandler(value = LoginFailException.class)
    @ResponseBody
    public RemoteResult loginFailExceptionExceptionHandler(HttpServletResponse response, Exception exception) {
        if (logger.isDebugEnabled()) {
            logger.debug("MyExceptionHandler-登录凭证已过期，请重新登录");
        } else {
            logger.info("MyExceptionHandler-登录凭证已过期，请重新登录");
        }
        StackTraceElement[] stackTrace = exception.getStackTrace();
        logger.info(Arrays.toString(stackTrace));
        response.setStatus(401);
        return new RemoteResult(false, 401, exception.getMessage());
    }

}
